package com.hzspace.springdataredis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class SpringDataRedisApplication {

  public static void main(String[] args) {
    SpringApplication.run(SpringDataRedisApplication.class, args);
  }


  @Autowired
  RedisTemplate redisTemplate;
  @Autowired
  StringRedisTemplate stringRedisTemplate;

  @GetMapping("/hello")
  public Object hello(){
//    redisTemplate.setKeySerializer(new StringRedisSerializer());
    ValueOperations ops = redisTemplate.opsForValue();
    ops.set("k1", "v1");
    Object v1 = ops.get("k1");
    System.out.println(v1);

    ValueOperations ops1 = stringRedisTemplate.opsForValue();
    ops1.set("k2", "v2");
    Object v2 = ops1.get("k2");
    System.out.println(v2);
    return "OK";
  }

}
